package com.niit.spark.rdd.test

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * Date:2025/5/6
 * Author：Ys
 * Description:
 */
object FlatMapExercise {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("FlatMapExercise")
    val sc = new SparkContext(sparkConf)
    sc.setLogLevel("ERROR")
    val textRDD = sc.parallelize(Seq("Hello, world! Spark is great.", "This is a test.Data analysis with Spark."))


    val resRdd: RDD[String] = textRDD.flatMap(line => {

      line.replaceAll("[^a-zA-Z0-9\\s]", "").split("\\s+")

    })

    resRdd.collect().foreach(println)

    sc.stop()
  }
}


